package com.tong.controller;

import com.tong.entity.Category;
import com.tong.result.Response;
import com.tong.result.ResponseResult;
import com.tong.service.CategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 分类(Category)表控制层
 *
 * @author makejava
 * @since 2021-07-30 09:56:13
 */
@RestController
@RequestMapping("categories")
public class CategoryController {
    /**
     * 服务对象
     */
    @Resource
    private CategoryService categoryService;

    /**
     * 更新
     *
     * @param id
     * @param category
     * @return
     */
    @PatchMapping("{id}")
    public ResponseResult update(@PathVariable Integer id, @RequestBody Category category) {
        category.setId(id);
        return Response.makeOKRsp(categoryService.update(category));
    }

    /**
     * 列表
     *
     * @return
     */
    @GetMapping
    public ResponseResult categories() {
        return Response.makeOKRsp(categoryService.getByFirstLevel());
    }
}